package requests.info.schedule;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import requests.settings.Settings;

public class Plan extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel panel;
	private JLabel labels[][];
	private Color backgroundColor = new Color(0,0,0),
				  daysColor = new Color(0,130,255),
				  hoursColor = new Color(255,130,0),
				  deactiveColor = new Color(255,255,255),
				  AiDSColor = new Color(60,255,0),
				  WstepColor = new Color(255,100,190),
				  WykladColor = new Color(160,190,90),
				  TechnologieColor = new Color(250,50,50),
				  ProgColor = new Color(160,160,160),
				  PodstColor = new Color(160,110,230),
				  DysColor = new Color(0,255,255);
	private int numberOfColumns = 6, numberOfRows = 8;
	private Font font = new Font("Times New Roman", 1, 16),
				 labelFont = new Font("Times New Roman", 1, 24);
	
	
	public Plan(int width, int heigth, Settings settings) {
		
		setSize(width, heigth);
		setLocation(200,200);
		setVisible(true);
		setResizable(false);
		setTitle("D.E.M.I. - Plan Tygodnia");
		
		GridBagLayout layout = new GridBagLayout();
		int k = 172;
		int l = 70;
        layout.columnWidths = new int[] { k,k,k,k,k,k };
        layout.rowHeights = new int[] { l,l,l,l,l,l,l,l };
        
		panel = new JPanel(layout);
		panel.setBackground(backgroundColor);
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(2,2,2,2);
		add(panel);
		
		labels = new JLabel[numberOfColumns][numberOfRows];
		String labelText[][] = new String[numberOfColumns][numberOfRows];
		
		for (int i = 0; i < numberOfColumns; i++) 
			for (int j = 0; j < numberOfRows; j++) 
				labelText[i][j] = settings.getSettings("Plan<"+i+","+j+">");
		
		
		for (int i = 0; i < numberOfColumns; i++) {
			for (int j = 0; j < numberOfRows; j++) {
				labels[i][j] = new JLabel(labelText[i][j]);
				labels[i][j].setHorizontalAlignment(SwingConstants.CENTER);
				labels[i][j].setOpaque(true);
				labels[i][j].setFont(font);
				c.gridx = i;
				c.gridy = j;
				panel.add(labels[i][j], c);
				
				if (j == 0 || i == 0)
					labels[i][j].setFont(labelFont);
				
				if (i == 0) 
					labels[i][j].setBackground(hoursColor);
				else if (j == 0)
					labels[i][j].setBackground(daysColor);
				else if (labelText[i][j].length() > 2) {
					if (labelText[i][j].substring(6,8).equals("Ai")) 
						labels[i][j].setBackground(AiDSColor);
					else if (labelText[i][j].substring(6,8).equals("Ma"))
						labels[i][j].setBackground(DysColor);
					else if (labelText[i][j].substring(6,8).equals("Ws"))
						labels[i][j].setBackground(WstepColor);
					else if (labelText[i][j].substring(6,8).equals("Wy"))
						labels[i][j].setBackground(WykladColor);
					else if (labelText[i][j].substring(6,8).equals("Pr"))
						labels[i][j].setBackground(ProgColor);
					else if (labelText[i][j].substring(6,8).equals("Te"))
						labels[i][j].setBackground(TechnologieColor);
					else if (labelText[i][j].substring(6,8).equals("Po"))
						labels[i][j].setBackground(PodstColor);
				}
				else
					labels[i][j].setBackground(deactiveColor);
			}
		}
		
	}

}
